package com.glasgowrax.domain.directions;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Line {
	
	private String name;
	private String shortName;
	private String colour;
	private String textColour;	
	private String url;
	private String iconUrl;	
	private Vehicle vehicle;
	private List<Agency> agencies;
	
	public Line(JSONObject json) {
		
		try {
			JSONObject jsonVehicle = (json.has("vehicle")) ? json.getJSONObject("vehicle") : new JSONObject();
			JSONArray jsonAgencies = (json.has("agencies")) ? json.getJSONArray("agencies") : new JSONArray();
			
			name = (json.has("name")) ? json.getString("name") : "";		
			shortName = (json.has("short_name")) ? json.getString("short_name") : "";
			colour = (json.has("color")) ? json.getString("color") : "";
			textColour = (json.has("text_colour")) ? json.getString("text_colour") : "";
			url = (json.has("url")) ? json.getString("url") : "";
			iconUrl = (json.has("icon")) ? json.getString("icon") : "";
						
			vehicle = new Vehicle(jsonVehicle);
			
			agencies = new ArrayList<Agency>();
			for (int i=0; i<jsonAgencies.length(); i++) {
				agencies.add(new Agency(jsonAgencies.getJSONObject(i)));
			}			
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public String getColour() {
		return colour;
	}

	public void setColour(String colour) {
		this.colour = colour;
	}

	public String getTextColour() {
		return textColour;
	}

	public void setTextColour(String textColour) {
		this.textColour = textColour;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getIconUrl() {
		return iconUrl;
	}

	public void setIconUrl(String iconUrl) {
		this.iconUrl = iconUrl;
	}

	public Vehicle getVehicle() {
		return vehicle;
	}

	public void setVehicle(Vehicle vehicle) {
		this.vehicle = vehicle;
	}

	public List<Agency> getAgencies() {
		return agencies;
	}

	public void setAgencies(List<Agency> agencies) {
		this.agencies = agencies;
	}
	
	
	
}
